#include "sct/rtspserver/amrservermediasubsession.h"
#include "AMRAudioRTPSink.hh"
#include "sct/rtspserver/amrsource.h"

namespace sct
{

CAMRServerMediaSubsession*
CAMRServerMediaSubsession::createNew(UsageEnvironment& env,
		void* audio,
					     Boolean reuseFirstSource) {
  return new CAMRServerMediaSubsession(env, audio, reuseFirstSource);
}

CAMRServerMediaSubsession
::CAMRServerMediaSubsession(UsageEnvironment& env,
		void* audio, Boolean reuseFirstSource)
  : FileServerMediaSubsession(env, "", reuseFirstSource) {
	mAudioSource = audio;
}

CAMRServerMediaSubsession
::~CAMRServerMediaSubsession() {
}

FramedSource* CAMRServerMediaSubsession
::createNewStreamSource(unsigned /*clientSessionId*/, unsigned& estBitrate) {
  estBitrate = 10; // kbps, estimate

  return CAMRSource::createNew(envir(), mAudioSource);
}

RTPSink* CAMRServerMediaSubsession
::createNewRTPSink(Groupsock* rtpGroupsock,
		   unsigned char rtpPayloadTypeIfDynamic,
		   FramedSource* inputSource) {
  CAMRSource* amrSource = (CAMRSource*)inputSource;
  return AMRAudioRTPSink::createNew(envir(), rtpGroupsock,
				    rtpPayloadTypeIfDynamic,
				    amrSource->isWideband(),
				    amrSource->numChannels());
}

}
